import akshare as ak
import sqlite3
import pandas as pd


stock_board_concept_name_em = ak.stock_board_concept_name_em()
stock_board_concept_cons_em = ak.stock_board_concept_cons_em("海工装备")
stock_board_concept_hist_em = ak.stock_board_concept_hist_em(symbol="海工装备",start_date='20250301',end_date='20990101')
stock_board_concept_hist_min_em = ak.stock_board_concept_hist_min_em("海工装备")

with sqlite3.connect("example.db") as conn:
    stock_board_concept_name_em.to_sql("stock_board_concept_name_em",conn,if_exists='replace',index=False)
    stock_board_concept_cons_em.to_sql("stock_board_concept_cons_em",conn,if_exists='replace',index=False)
    stock_board_concept_hist_em.to_sql("stock_board_concept_hist_em",conn,if_exists='replace',index=False)
    stock_board_concept_hist_min_em.to_sql("stock_board_concept_hist_min_em",conn,if_exists='replace',index=False)

# stock_board_industry_name_em = ak.stock_board_industry_name_em()

# with sqlite3.connect("example.db") as conn:
#     stock_board_industry_name_em.to_sql("stock_board_industry_name_em",conn,if_exists='replace',index=False)

# stock_concept_cons_futu = ak.stock_concept_cons_futu()
# stock_concept_flow_hist = ak.stock_concept_fund_flow_hist("大飞机")

# stock_main_fund_flow = ak.stock_main_fund_flow("沪深A股")

# with sqlite3.connect("example.db") as conn:
#     # stock_concept_cons_futu.to_sql("stock_concept_cons_futu",conn,if_exists="replace",index=False)
#     # stock_concept_flow_hist.to_sql("stock_concept_flow_hist",conn,if_exists="replace",index=False)
#     stock_main_fund_flow.to_sql("stock_main_fund_flow",conn,if_exists="replace",index=False)

# stock_zh_a_hist_df = ak.stock_zh_a_hist(symbol="002642", period="daily", start_date="20240209", end_date='20250209', adjust="")

# print(stock_zh_a_hist_df)
# df_stock = ak.stock_individual_fund_flow(stock="002642", market="sz")

# print(df_stock.head())
# with sqlite3.connect("example.db") as conn:
#     stock_zh_a_hist_df.to_sql("stock_zh_a_hist_df_002642",conn,if_exists="replace",index=False)
#     df_stock.to_sql("df_stock_002642",conn,if_exists="replace",index=True)
# df_sz = ak.stock_info_sz_name_code(symbol="A股列表")

# stock_board_concept_name_em = ak.stock_board_concept_name_em()
# spot_price = ak.futures_spot_price()
# print(spot_price)
# with sqlite3.connect("example.db") as conn:stock_board_concept_name_em.to_sql("stock_board_concept_name_em",conn,if_exists="replace",index=False)


# stock_hsgt_board_rank_em = ak.stock_hsgt_board_rank_em()
# with sqlite3.connect("example.db") as conn:
#     stock_hsgt_board_rank_em.to_sql("stock_hsgt_board_rank_em",conn,if_exists="replace",index=False)


# stock_board_concept_cons_em = ak.stock_board_concept_cons_em("小金属概念")
# with sqlite3.connect("example.db") as conn:
#     stock_board_concept_cons_em.to_sql("stock_board_concept_cons_em",conn,if_exists="replace",index=False)
# stock_board_change_em = ak.stock_board_change_em()
# print(stock_board_change_em)
# with sqlite3.connect("example.db") as conn:
#     stock_board_change_em.to_sql("stock_board_change_em",conn,if_exists="replace",index=False)

# with sqlite3.connect("example.db") as conn:
#     df = pd.read_sql("select * from stock_board_industry_name_ths",conn)
#     for item in df['name']:
#         stock_board_industry_info_ths = ak.stock_board_industry_info_ths(f"{item}")
#         stock_board_industry_info_ths.to_sql(f"stock_board_industry_info_ths_{item}",conn,if_exists="replace",index=False)


# stock_board_industry_cons_em = ak.stock_board_industry_cons_em()
# with sqlite3.connect("example.db") as conn:
#     stock_board_industry_cons_em.to_sql("stock_board_industry_cons_em",conn,if_exists="replace",index=False)

